package com.wyx.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 王艺锡
 * @version 1.0
 * 分组
 */
public class regExp05 {
    public static void main(String[] args) {
        String content = "dklh1175 wyx 8896da";
        //非命名分组
        //matcher.group(0)--得到匹配的全部字符串
        //matcher.group(1)--得到匹配的字符串分组的第一组内容
        //matcher.group(0)--得到匹配的字符串分组的第二组内容

        //String regStr = "(\\d\\d)(\\d\\d)";


        //命名分组
        String regStr = "(?<g1>\\d\\d)(?<g2>\\d\\d)";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println("找到" + matcher.group(0));
            System.out.println("第一组" + matcher.group(1));
            System.out.println("第一组[命名分组]" + matcher.group("g1"));
            System.out.println("第二组" + matcher.group(2));
            System.out.println("第二组[命名分组]" + matcher.group("g2"));
        }

    }
}
